﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaxBusiness.DAL;
using TaxBusiness.Model;

namespace TaxBusiness.BLL
{
    public class CustomerBLL
    {
        public int Save(Customer customer)
        {
            CustomerDB customerdb = new CustomerDB();
            return customerdb.Save(customer);
        }

        public int Update(Customer customer)
        {
            CustomerDB customerdb = new CustomerDB();
            return customerdb.Update(customer);
        }

        public int Delete(string id)
        {
            string[] ids = id.Split(',');
            int[] idArray = Array.ConvertAll(ids, s => int.Parse(s));
            CustomerDB customerdb = new CustomerDB();
            return customerdb.Delete(idArray);
        }

        public List<Customer> GetLlist(int pageSize, int pageIndex, string whereStr, string keyWord, string order, out int count)
        {
            CustomerDB customerdb = new CustomerDB();
            List<Model.Customer> customerlist = new List<Customer>();
            count = customerdb.GetCount(whereStr);
            customerlist = customerdb.GetAll(pageSize, pageIndex, whereStr, order, keyWord);
            return customerlist;
        }

        public List<Customer> GetLlist(string searchWord)
        {
            CustomerDB customerdb = new CustomerDB();
            List<Model.Customer> customerlist = new List<Customer>();
            customerlist = customerdb.GetLike(searchWord);
            return customerlist;
        }

        public string MakeWhereString(int authid, int keyid, string customer)
        {
            string c = " exists (select customerid from tb_business where customerid=customer.id{0}){1}";
            string c0 = " ";
            string c1 = " ";
            if (authid == 1)
                c0 += "and fillinid=" + keyid;
            else if (keyid > 0)
                c0 += "and theoffice=" + keyid;
            if (customer != "")
                c1 += "and TheName like '%" + customer + "%'";
            c = string.Format(c,c0, c1);
            return c;
        }
    }
}
